package com.smartsofa.photo;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;
import java.util.List;

import com.smartsofa.R;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.view.View;
import android.widget.GridView;
import android.widget.Toast;

public class ShowImageActivity extends Activity {
	private GridView mGridView;
	private List<String> List;
	private ChildAdapter adapter;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.show_image_activity);
		
		mGridView = (GridView) findViewById(R.id.child_grid);
		List = getIntent().getStringArrayListExtra("data");
		
		adapter = new ChildAdapter(this, List, mGridView,mHandler);
		mGridView.setAdapter(adapter);
		
	}
	
	Handler mHandler = new Handler() {
		@Override
		public void handleMessage(Message msg) {
			switch (msg.what) {
			case 0:
				Toast.makeText(ShowImageActivity.this, "最多选择1张图片", 400).show();
				break;

			default:
				break;
			}
		}
	};

	/*@Override
	public void onBackPressed() {
		Toast.makeText(this, "选中 " + adapter.getSelectItems().size() + " item", Toast.LENGTH_LONG).show();
		super.onBackPressed();
	}*/
	
	public void imageback(View v) { // 标题栏 返回按钮
		this.finish();
	}
	
	public void quxiao(View v) { // 标题栏 取消按钮
		PhotoScan.instance.finish();
		this.finish();
	}
	
	
	public void finish(View v) { // 完成按钮
		ArrayList<String> list = new ArrayList<String>();
		List<Integer> c = adapter.getSelectItems();
		Iterator<Integer> it = c.iterator();
		for (; it.hasNext();) {
			list.add(List.get(it.next()));
		}
		for (int i = 0; i < list.size(); i++) {
			if (Bimp.drr.size() < 8) {
				Bimp.drr.add(list.get(i));
			}
		}
		
		PhotoScan.instance.finish();
		this.finish();
	}

	
}
